<?php

namespace app\system\controller;

use app\common\model\AdminModel;
use helper\Files;
use think\facade\Cookie;
use think\facade\Session;

class IndexController extends BaseController
{

  /**
   * 不需要登陆的方法
   * @var array
   */
  protected $noLogin = [];

  /**
   * 不检测权限方法
   * @var array
   */
  protected $noCheck = ['*'];

  /**
   * 初始化
   */
  public function __construct()
  {
    parent::__construct();
  }

  /**
   * 首页
   * @return string
   * @throws \Exception
   */
  public function index()
  {
    $user = AdminModel::withoutField('password,salt')
      ->where('id', $this->loginInfo['uid'])
      ->find();
    $this->assign('user', $user);
    return $this->fetch();
  }

  /**
   * 主页
   */
  public function main()
  {
    echo $this->request->action(true);
  }

  /**
   * 清空缓存
   */
  public function clear()
  {
    $runtimePath = app()->getRuntimePath() . 'system';
    Files::unlinkDir($runtimePath);
    $this->success('清理缓存成功');
  }

  /**
   * 退出登录
   */
  public function quit()
  {
    Session::delete('_auth_list_'.$this->loginInfo['uid']);
    Cookie::delete('system_token');
    $this->success('退出成功');
  }
}
